package spotor.client.ui;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import spotor.client.provider.SpotorContract.Plans;
import spotor.client.util.Lists;
import spotor.client.util.PlanSimpleAdapter;
import spotor.client.R;
import spotor.client.R.id;
import spotor.client.R.layout;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class PlansActivity extends ListActivity {

	private static final String TAG = "Plan Activity";
	List<String> data;
	List<Map<String, Object>> plan_list;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_plans);
		plan_list = getPlanList();
		PlanSimpleAdapter adapter = new PlanSimpleAdapter(this, plan_list,
				R.layout.plan_item, new String[] { "Title", "miaoshu", "img" },
				new int[] { R.id.textView1, R.id.miaoshu, R.id.plan_logo });
		setListAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
	}

	public List<Map<String, Object>> getPlanList() {
		plan_list = Lists.newArrayList();

		return plan_list;
	}

	private class PlanAdapter extends CursorAdapter {
		public PlanAdapter(Context context) {
			super(context, null);
			// TODO Auto-generated constructor stub
		}

		@Override
		public View newView(Context context, Cursor cursor, ViewGroup parent) {
			// TODO Auto-generated method stub
			return getLayoutInflater().inflate(R.layout.list_item_plan, parent,
					false);
		}

		@Override
		public void bindView(View view, Context context, Cursor cursor) {
			// 绑定计划的各个字段
			final TextView titleView = (TextView)view.findViewById(R.id.plan_title);
			final TextView contentView = (TextView)view.findViewById(R.id.plan_cotent);
			final TextView placeView = (TextView)view.findViewById(R.id.plan_place);
			titleView.setText(cursor.getString(PlansQuery.PLAN_TITLE));
			contentView.setText(cursor.getString(PlansQuery.PLAN_CONTENT));
			
		}
	}
	
	/*{@link Plans} query parameters. */
	private interface PlansQuery{
		String[] PROJECTION = {
				BaseColumns._ID,
				Plans.PLAN_TITLE,
				Plans.PLAN_CONTENT,
				Plans.PLACE_NAME,
		};
		
		int _ID = 0;
		int PLAN_TITLE = 1;
		int PLAN_CONTENT = 2;
		int PLAN_PLACE_NAME = 3;
	}

}
